<?php
/**
 * 经销商拜访
 * Created by PhpStorm.
 * User: g
 * Date: 2018/3/13
 * Time: 17:38
 */

namespace app\index\controller;


class Jxsbf extends Common
{
    /**
     *我的经销商拜访
     * @return mixed
     */
    public function myagencybf(){
        $jxs_title = $this->request->param('jxs_title');
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $this->assign('jxs_title',$jxs_title);
        $this->assign('start',$start);
        $this->assign('end',$end);
        $where = [];
        if($jxs_title){
            $where['jxs_title'] = ['like','%'.'%'];
        }
        if($start&&!$end){
            $where['bgrq'] = ['>=',$start];
        }elseif(!$start&&$end){
            $where['bgrq'] = ['<=',$end];
        }elseif($start&&$end){
            $where['bgrq'] = [['>=',$start],['<=',$end],'and'];
        }
        $cnt = db('yd_jxsbf')->where($where)->count();
        $data = db('yd_jxsbf')->where($where)->paginate(10,$cnt);
        $page = $data->render();
        $data = $data->items();
        $this->assign([
            'page'=>$page,
            'data'=>$data,
        ]);
        return $this->fetch();
    }

    /**
     * 下属的经销商拜访
     * @return mixed
     */
    public function xiashuagencybf(){
        $jxs_title = $this->request->param('jxs_title');
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $bfr_name = $this->request->param('bfr_name');
        $bfrbm = $this->request->param('bfrbm');
        $this->assign('jxs_title',$jxs_title);
        $this->assign('start',$start);
        $this->assign('end',$end);
        $this->assign('bfrbm',$bfrbm);
        $this->assign('bfr_name',$bfr_name);

        $where = [];
        //查询我负责的部门下属的所有人员
        $bmids = db('department t')->join('department_employee t2','t.id=t2.department_id')->where(['t.principal'=>session('emplyee_id'),'t2.index'=>1])->column('t2.employee_id');
        $where['bfr'] = ['in',$bmids];

        if($jxs_title){
            $where['jxs_title'] = ['like','%'.'%'];
        }
        if($start&&!$end){
            $where['bgrq'] = ['>=',$start];
        }elseif(!$start&&$end){
            $where['bgrq'] = ['<=',$end];
        }elseif($start&&$end){
            $where['bgrq'] = [['>=',$start],['<=',$end],'and'];
        }
        if($bfrbm){
            $where['bfrbm'] = ['like','%'.$bfrbm.'%'];
        }
        if($bfr_name){
            $where['bfr_name'] = ['like','%'.$bfr_name.'%'];
        }
        $cnt = db('yd_jxsbf')->where($where)->count();
        $data = db('yd_jxsbf')->where($where)->paginate(10,$cnt);
        $page = $data->render();
        $data = $data->items();
        $this->assign([
            'page'=>$page,
            'data'=>$data,
        ]);
        return $this->fetch();
    }

    /**
     * 所有经销商拜访
     * @return mixed
     */
    public function allagencybf(){
        $jxs_title = $this->request->param('jxs_title');
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $bfr_name = $this->request->param('bfr_name');
        $bfrbm = $this->request->param('bfrbm');
        $this->assign('jxs_title',$jxs_title);
        $this->assign('start',$start);
        $this->assign('end',$end);
        $this->assign('bfrbm',$bfrbm);
        $this->assign('bfr_name',$bfr_name);

        $where = [];

        if($jxs_title){
            $where['jxs_title'] = ['like','%'.'%'];
        }
        if($start&&!$end){
            $where['bgrq'] = ['>=',$start];
        }elseif(!$start&&$end){
            $where['bgrq'] = ['<=',$end];
        }elseif($start&&$end){
            $where['bgrq'] = [['>=',$start],['<=',$end],'and'];
        }
        if($bfrbm){
            $where['bfrbm'] = ['like','%'.$bfrbm.'%'];
        }
        if($bfr_name){
            $where['bfr_name'] = ['like','%'.$bfr_name.'%'];
        }
        $cnt = db('yd_jxsbf')->where($where)->count();
        $data = db('yd_jxsbf')->where($where)->paginate(10,$cnt);
        $page = $data->render();
        $data = $data->items();
        $this->assign([
            'page'=>$page,
            'data'=>$data,
        ]);
        return $this->fetch();
    }
}